//
//  ZBHTTPService+ResultData.m
//  BaseRACDemo
//
//  Created by Angel_Yan on 2018/3/28.
//  Copyright © 2018年 庄波. All rights reserved.
//

#import "ZBHTTPService+ResultData.h"
#import "ZBResultModel.h"

@implementation ZBHTTPService (ResultData)
- (RACSignal *)fetchResultWithUserToken:(NSString *)userToken size:(NSInteger)size page:(NSInteger)page;
{
    /// 1. 配置参数
    MHKeyedSubscript *subscript = [MHKeyedSubscript subscript];
    subscript[@"pageSize"] = @(size);
    subscript[@"pageIndex"] = @(page);
    subscript[@"token"] = userToken;
    /// 2. 配置参数模型 #define MH_GET_LIVE_ROOM_LIST  @"Room/GetHotLive_v2"
    MHURLParameters *paramters = [MHURLParameters urlParametersWithMethod:MH_HTTTP_METHOD_GET path:MH_GET_Result parameters:subscript.dictionary];
    
    /// 3.发起请求
    return [[[MHHTTPRequest requestWithParameters:paramters]
             enqueueResultClass:[ZBResultModel class]]
            mh_parsedResults];
}

- (RACSignal *)sendMessagteWithPhone:(NSArray*)phone withTemplate:(NSString*)str withToken:(NSString*)token{
    MHKeyedSubscript *subscript = [MHKeyedSubscript subscript];

    for (NSString *phoneStr in phone) {
        subscript[@"phone"] = phoneStr;
    }
    
    subscript[@"template"] = str;
    subscript[@"token"] = token;
    subscript[@"address"] = @"五大花园";
    
    /// 2. 配置参数模型 #define MH_GET_LIVE_ROOM_LIST  @"Room/GetHotLive_v2"
    MHURLParameters *paramters = [MHURLParameters urlParametersWithMethod:MH_HTTTP_METHOD_GET path:MH_GET_Sendmessgate parameters:subscript.dictionary];
    
    /// 3.发起请求
    return [[MHHTTPRequest requestWithParameters:paramters]
             enqueueResultClass:[ZBObject class]];
}

- (RACSignal *)getTemplatewithToken:(NSString*)token{
    MHKeyedSubscript *subscript = [MHKeyedSubscript subscript];
    subscript[@"token"] = token;
    MHURLParameters *paramters = [MHURLParameters urlParametersWithMethod:MH_HTTTP_METHOD_GET path:MH_GET_TempLate parameters:subscript.dictionary];
    
    /// 3.发起请求
    return [[[[MHHTTPRequest requestWithParameters:paramters]
             enqueueResultClass:[ZBTemplateModel class]] mh_parsedResults] map:^id _Nullable(NSString * value) {
        ZBUserOwn *own = [[ZBHTTPService sharedInstance] currentUser];
        value = [[[value stringByReplacingOccurrencesOfString:@"{0}" withString:own.company]stringByReplacingOccurrencesOfString:@"{2}" withString:own.userName] stringByReplacingOccurrencesOfString:@"{1}" withString:@"五大花园"];
        return value;
    }];
}
@end
